% To calculate transition prob & its standardized one
clear all;
clc;
disp('To calculate yearly transition prob & its standardized one');
load TP06_Y_RJ_fin_R5_G1000k_MR7.mat
% freqj=4;% 4 quarters
year_list=[1997:2009]';
year_list_text=num2str(year_list);
% quarter_list=[1:4]';
% quarter_list_text=num2str(quarter_list);
Rate_list=[0,1:0.5:5];
prob=zeros(13,10,12);% the last column will be 1, so we ignore the 13th column and set it as 12 columns
prob_std=zeros(13,10,12); % the 12th column is useless, we define 12 column for coding conveinence.
% filename1='TP06_Y_RJ_fin_R5_G1000k_MR7_transition prob.xls';
% filename2='TP06_Y_RJ_fin_R5_G1000k_MR7_transition prob_std.xls';


for i=1:13
%     for j=1:freqj
        for ii=1:length(Rate_list)
            for jj=1:12
                prob(i,ii,jj) = final_result(i,ii,jj)/final_result(i,ii,13);
            end
        end
%         xx(:,:)=prob(i,:,:);
%         sheetlist=strcat('',year_list_text(i,:),'');
%         xlswrite(filename1, xx, sheetlist);
%         clear xx sheetlist
%     end
end

for i=1:13
%     for j=1:freqj
        for ii=1:length(Rate_list)
            for jj=1:12
                prob_std(i,ii,jj) = prob(i,ii,jj)/(1-prob(i,ii,12));
            end
        end
%         xx(:,:)=prob_std(i,:,:);
%         sheetlist=strcat('',year_list_text(i,:),'');
%         xlswrite(filename2, xx, sheetlist);
%         clear xx sheetlist
%     end
end
